package com.yitao.client.constant;

import com.skipper.base.bean.DataOutput;
import com.yitao.client.dto.enums.EnumDto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: wwl
 * @Date: 2019/5/6 17:33
 * @Description:
 */
public class RollinInventoryEnums {


    public enum InventoryStatusEnum {

        IN_THE_MATCH(0, "匹配中"),
        MATCHING_COMPLETE(1, "匹配完成"),
        HAVE_OUTBOUND(2, "已出库 ");

        private static final Map<Integer, InventoryStatusEnum> map = new HashMap<>();

        static {
            InventoryStatusEnum[] values = InventoryStatusEnum.values();
            for (InventoryStatusEnum item : values) {
                map.put(item.code, item);
            }
        }

        private final Integer code;
        private final String name;

        private InventoryStatusEnum(Integer code, String name) {
            this.code = code;
            this.name = name;
        }

        public static InventoryStatusEnum getEnum(Integer code) {
            return map.get(code);
        }

        public Integer getCode() {
            return code;
        }

        public String getName() {
            return name;
        }
    }


    /**
     * 调拨类型
     */
    public enum AllotHistoryType {

        ADD(1, "+"),
        MINUS(0, "-");
        private static final List<EnumDto> list = new ArrayList<>();
        private static final HashMap<Integer, String> map = new HashMap<>();

        static {
            for (RollinInventoryEnums.AllotHistoryType e : RollinInventoryEnums.AllotHistoryType.values()) {
                EnumDto enumDto = new EnumDto();
                enumDto.setCode(e.code);
                enumDto.setDesc(e.desc);
                list.add(enumDto);
                map.put(e.code, e.desc);
            }
        }

        private Integer code;
        private String desc;

        AllotHistoryType(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        /**
         * 枚举列表
         *
         * @return
         */
        public static DataOutput findAllotHistoryType() {
            return new DataOutput(list);
        }

        /**
         * 根据编码查询描述
         *
         * @param code
         * @return
         */
        public static String getMsgByCode(Integer code) {
            return map.get(code);
        }

    }

    /**
     * 库存类型
     */
    public enum InventoryType {

        PROCUREMENT(2, "采购车库存"),
        WAREHOUSE(1, "仓库库存");
        private static final List<EnumDto> list = new ArrayList<>();
        private static final HashMap<Integer, String> map = new HashMap<>();

        static {
            for (RollinInventoryEnums.InventoryType e : RollinInventoryEnums.InventoryType.values()) {
                EnumDto enumDto = new EnumDto();
                enumDto.setCode(e.code);
                enumDto.setDesc(e.desc);
                list.add(enumDto);
                map.put(e.code, e.desc);
            }
        }

        private Integer code;
        private String desc;

        InventoryType(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        /**
         * 枚举列表
         *
         * @return
         */
        public static DataOutput findInventoryType() {
            return new DataOutput(list);
        }

        /**
         * 根据编码查询描述
         *
         * @param code
         * @return
         */
        public static String getMsgByCode(Integer code) {
            return map.get(code);
        }

    }

    /**
     * 库存类型
     */
    public enum AllotState {

        PENDING(0, "待处理"),
        PROCESSED(1, "已处理");
        private static final List<EnumDto> list = new ArrayList<>();
        private static final HashMap<Integer, String> map = new HashMap<>();

        static {
            for (RollinInventoryEnums.AllotState e : RollinInventoryEnums.AllotState.values()) {
                EnumDto enumDto = new EnumDto();
                enumDto.setCode(e.code);
                enumDto.setDesc(e.desc);
                list.add(enumDto);
                map.put(e.code, e.desc);
            }
        }

        private Integer code;
        private String desc;

        AllotState(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        /**
         * 枚举列表
         *
         * @return
         */
        public static DataOutput findAllotState() {
            return new DataOutput(list);
        }

        /**
         * 根据编码查询描述
         *
         * @param code
         * @return
         */
        public static String getMsgByCode(Integer code) {
            return map.get(code);
        }

    }

    /**
     * 单据类型
     */
    public enum DocumentType {

        PURCHASING_STORAGE(0, "采购入库单"),
        SALES_OUTBOUND(1, "销售出库单"),
        ALLOT_OUTBOUND(2, "调拨出库单"),
        ALLOT_STORAGE(3, "调拨入库单");
        private static final List<EnumDto> list = new ArrayList<>();
        private static final HashMap<Integer, String> map = new HashMap<>();

        static {
            for (RollinInventoryEnums.DocumentType e : RollinInventoryEnums.DocumentType.values()) {
                EnumDto enumDto = new EnumDto();
                enumDto.setCode(e.code);
                enumDto.setDesc(e.desc);
                list.add(enumDto);
                map.put(e.code, e.desc);
            }
        }

        private Integer code;
        private String desc;

        DocumentType(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        /**
         * 枚举列表
         *
         * @return
         */
        public static DataOutput findDocumentTypeType() {
            return new DataOutput(list);
        }

        /**
         * 根据编码查询描述
         *
         * @param code
         * @return
         */
        public static String getMsgByCode(Integer code) {
            return map.get(code);
        }

        public static Integer getAllotHistoryTypeByDocumentType(Integer code) {
            if (code == 0 || code == 3) {
                return AllotHistoryType.ADD.code;
            } else if (code == 1 || code == 2) {
                return AllotHistoryType.MINUS.code;
            }
            return null;
        }
    }

}
